home *** CD-ROM | disk | FTP | other *** search
/ Hot Super Models / Hot Super Models.iso / unix / x11 / xv2r1.tar / xv2r1 / extensions / xv / clients / vset.c < prev   
C/C++ Source or Header  |  1991-09-05  |  8KB  |  313 lines

  1. #ifndef lint    /* BuildSystemHeader added automatically */
  2. static char *BuildSystemHeader= "$Header$";    /* BuildSystemHeader */
  3. #endif        /* BuildSystemHeader */
  4.  
  5. /***********************************************************
  6. Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
  7. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  8.   
  9.                         All Rights Reserved
  10.   
  11. Permission to use, copy, modify, and distribute this software and its 
  12. documentation for any purpose and without fee is hereby granted, 
  13. provided that the above copyright notice appear in all copies and that
  14. both that copyright notice and this permission notice appear in 
  15. supporting documentation, and that the names of Digital or MIT not be
  16. used in advertising or publicity pertaining to distribution of the
  17. software without specific, written prior permission.  
  18.   
  19. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  21. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  23. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  24. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  25. SOFTWARE.
  26.   
  27. ******************************************************************/
  28. /*
  29.  * * File: *
  30.  *
  31.  *   vset.c: user preference utility for live video extension to X *
  32.  *
  33.  *   
  34.  *
  35.  * Author: *
  36.  *
  37.  *   Susan Angebranndt *
  38.  *
  39.  *       
  40.  *
  41.  */
  42.  
  43. #include <stdio.h>
  44. #include <X11/Xlib.h>
  45. #include <X11/Xutil.h>
  46. #include <X11/extensions/Xvlib.h>
  47.  
  48. typedef struct _Options {
  49.     Bool            brightness;
  50.     Bool            contrast;
  51.     Bool            hue;
  52.     Bool            saturation;
  53.     Bool            query;
  54.     Bool            encoding;
  55.     int            b;
  56.     int            c;
  57.     int            h;
  58.     int            s;
  59.     char *        e;
  60.     char *        displayName;
  61. } Options;
  62.  
  63. static void Usage()
  64. {
  65.     printf("vset [-d display] [-b integer] [-c integer] [-h integer]\n");
  66.     printf("[-s integer] [-e encoding] [-q]\n");
  67.     printf("\nEncoding is one of:\n");
  68.     printf("    ntsc-composite\n");
  69.     printf("    pal-composite\n");
  70.     printf("    secam-composite\n");
  71.     printf("    ntsc-svideo\n");
  72.     printf("    pal-svideo\n");
  73.     printf("    secam-svideo\n");
  74.     printf("    ntsc-rgb\n");
  75.     printf("    pal-rgb\n");
  76.     printf("    secam-rgb\n");
  77.  
  78.     exit(1);
  79. }
  80.  
  81. Bool InternXvAtoms(dpy, encoding, saturation, hue, contrast, brightness)
  82.     Display        *dpy;
  83.     Atom           *encoding, *saturation, *hue, *contrast, *brightness;
  84. {
  85.     *encoding = XInternAtom(dpy, "XV_ENCODING", True);
  86.     if (*encoding == None)
  87.     return False;
  88.     *saturation = XInternAtom(dpy, "XV_SATURATION", True);
  89.     if (*saturation == None)
  90.     return False;
  91.     *hue = XInternAtom(dpy, "XV_HUE", True);
  92.     if (*hue == None)
  93.     return False;
  94.     *contrast = XInternAtom(dpy, "XV_CONTRAST", True);
  95.     if (*contrast == None)
  96.     return False;
  97.     *brightness = XInternAtom(dpy, "XV_BRIGHTNESS", True);
  98.     if (*brightness == None)
  99.     return False;
  100.     return True;
  101. }
  102.  
  103.  
  104. static void CheckEncodingName(str)
  105.     char *str;
  106. {
  107.     if (strcmp("ntsc-composite", str) == 0) {
  108.     return ;
  109.     } else if (strcmp("pal-composite", str) == 0) {
  110.     return ;
  111.     } else if (strcmp("secam-composite", str) == 0) {
  112.     return ;
  113.     } else if (strcmp("ntsc-svideo", str) == 0) {
  114.     return ;
  115.     } else if (strcmp("pal-svideo", str) == 0) {
  116.     return ;
  117.     } else if (strcmp("secam-svideo", str) == 0) {
  118.     return ;
  119.     } else if (strcmp("ntsc-rgb", str) == 0) {
  120.     return ;
  121.     } else if (strcmp("pal-rgb", str) == 0) {
  122.     return ;
  123.     } else if (strcmp("secam-rgb", str) == 0) {
  124.     return ;
  125.     } else {        /* no match */
  126.     Usage();
  127.     }
  128. }
  129.  
  130. static int ConvertToInteger(str)
  131.     char *str;
  132. {
  133.     int i;
  134.     int start;
  135.     if (str[0] == '-') 
  136.         start = 1;
  137.     else
  138.     start = 0;
  139.     for (i=start; i<strlen(str); i++) {
  140.     if (! isdigit(str[i])) Usage();
  141.     }
  142.     return atoi(str);
  143. }
  144.  
  145. static void ParseCommandLine(argv, argc, opts)
  146.     int    argc;
  147.     char *argv[];
  148.     Options *opts;
  149. {
  150.     int i;
  151.     int c;
  152.     extern char *optarg;
  153.     Bool foundOne = False;
  154.  
  155.     opts->brightness = False;
  156.     opts->contrast = False;
  157.     opts->hue = False;
  158.     opts->saturation = False;
  159.     opts->query = False;
  160.     opts->encoding = False;
  161.     opts->displayName = NULL;
  162.     
  163.     while ((c = getopt(argc, argv, "qd:b:c:h:s:e:")) != EOF) {
  164.     foundOne = True;
  165.     switch (c) {
  166.         case 'd':
  167.                 opts->displayName = optarg;
  168.         break;
  169.         case 'b':
  170.             opts->brightness = True;
  171.             opts->b = ConvertToInteger(optarg);
  172.         break;
  173.         case 'c':
  174.             opts->contrast = True;
  175.             opts->c = ConvertToInteger(optarg);
  176.         break;
  177.         case 'h':
  178.             opts->hue = True;
  179.             opts->h = ConvertToInteger(optarg);
  180.         break;
  181.         case 's':
  182.             opts->saturation = True;
  183.             opts->s = ConvertToInteger(optarg);
  184.         break;
  185.         case 'e':
  186.             opts->encoding = True;
  187.             opts->e = optarg;
  188.             CheckEncodingName(opts->e);
  189.         break;
  190.         case 'q':
  191.             opts->query = True;
  192.         break;
  193.         default:
  194.             Usage();
  195.     }
  196.     }
  197.     if (!foundOne) Usage();
  198. }
  199.  
  200. static void QueryAllInformation(dpy, port, 
  201.     batom, catom, hatom, satom, eatom, version, revision)
  202.     Display        *dpy;
  203.     XvPortID        port;
  204.     Atom            batom, catom, hatom, satom, eatom;    
  205.     int            version, revision;    
  206. {    
  207.     int value;
  208.     int             nEncodings;
  209.     XvEncodingInfo *encodingInfo;
  210.     XvEncodingInfo *a;
  211.     int i;
  212.  
  213.     printf("Xv V%01d.%d\n\n", version, revision);
  214.  
  215.     XvGetPortAttribute(dpy, port, eatom, &value);    
  216.     XvQueryEncodings(dpy, port, &nEncodings, &encodingInfo);
  217.     for (i = 0; i < nEncodings; i++) {
  218.     a = &encodingInfo[i];
  219.     if (a->encoding_id == value) {
  220.         printf("Encoding: %s\n", a->name);
  221.     }
  222.     }
  223.     XvGetPortAttribute(dpy, port, catom, &value);    
  224.     printf("Contast: %d\n", value);
  225.  
  226.     XvGetPortAttribute(dpy, port, hatom, &value);    
  227.     printf("Hue: %d\n", value);
  228.  
  229.     XvGetPortAttribute(dpy, port, satom, &value);    
  230.     printf("Saturation: %d\n", value);
  231.  
  232.     XvGetPortAttribute(dpy, port, batom, &value);    
  233.     printf("Brightness: %d\n", value);
  234.     XvFreeEncodingInfo(encodingInfo);
  235. }
  236.  
  237. int main(argc, argv)
  238.     int             argc;
  239.     char           *argv[];
  240. {
  241.     Display        *dpy;
  242.     int             version, revision, major_opcode;
  243.     int             event_base, error_base, status;
  244.     int             width, height;
  245.     XvRational      rate;
  246.     unsigned long   nAdaptors;
  247.     XvAdaptorInfo  *pAdaptors;
  248.     XvPortID        port;
  249.     Atom            batom, catom, hatom, satom, eatom;
  250.     Options        opts;
  251.     int            nEncodings;
  252.     XvEncodingInfo  *encodingInfo;
  253.     XvEncodingInfo  *a;
  254.     int            i;
  255.  
  256.     ParseCommandLine(argv, argc, &opts);
  257.  
  258.     dpy = XOpenDisplay(opts.displayName);
  259.     if (!dpy) {
  260.     printf("Couldn't open display %s\n", opts.displayName);
  261.     exit(-1);
  262.     }
  263.     status = XvQueryExtension(dpy, &version, &revision,
  264.                   &major_opcode, &event_base, &error_base);
  265.  
  266.     if (status != Success) {
  267.     printf("Xv video extension not available\n");
  268.     exit(-1);
  269.     }
  270.     if (! InternXvAtoms(dpy, &eatom, &satom, &hatom, &catom, &batom)) {
  271.     printf("Encoding atoms not set up properly\n");
  272.     exit(-1);
  273.     }
  274.  
  275.     XvQueryAdaptors(dpy, XDefaultRootWindow(dpy), &nAdaptors, &pAdaptors);
  276.     if (!nAdaptors) {
  277.     printf("Your display has no video adaptors\n");
  278.     exit(-1);
  279.     }
  280.     port = pAdaptors->base_id;
  281.  
  282.     if (opts.query) {
  283.     QueryAllInformation(dpy, port, 
  284.                 batom, catom, hatom, satom, eatom, 
  285.                 version, revision);
  286.     exit(0);
  287.     }
  288.     if (opts.brightness) {
  289.         XvSetPortAttribute(dpy, port, batom, opts.b);
  290.     }
  291.     if (opts.contrast) {
  292.         XvSetPortAttribute(dpy, port, catom, opts.c);
  293.     }
  294.     if (opts.hue) {
  295.         XvSetPortAttribute(dpy, port, hatom, opts.h);
  296.     }
  297.     if (opts.saturation) {
  298.         XvSetPortAttribute(dpy, port, satom, opts.s);
  299.     }
  300.     if (opts.encoding) {
  301.     XvQueryEncodings(dpy, port, &nEncodings, &encodingInfo);
  302.     for (i=0; i<nEncodings; i++) {
  303.         a = &encodingInfo[i];
  304.         if (strcmp(a->name, opts.e) == 0) {
  305.             XvSetPortAttribute(dpy, port, eatom, a->encoding_id);
  306.         break;        
  307.         }
  308.     }
  309.     XvFreeEncodingInfo(encodingInfo);
  310.     }
  311.     XSync(dpy, 0);
  312. }
  313.